<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>门店收入报表</title>
    <#include "/common/link.ftl" >

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl" >

    <#assign currentMenu="businessReport"/>

    <#include "/common/menu.ftl" >
    <div class="content-wrapper">
        <section class="content-header">
            <h1>门店收入报表</h1>
        </section>
        <section class="content">
            <div class="box">
                <div style="margin: 10px;">
                    <!--高级查询--->
                    <form class="form-inline" id="searchForm" action="/report/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label>门店查询</label>
                            <select class="form-control" name="businessId" id="businessId">
                                <option value="">请选择门店</option>
                                <#list businesses as tmp>
                                    <option value="${tmp.id}">${tmp.name}</option>
                                </#list>

                            </select>
                        </div>
                        <script>
                            $("#businessId").val(${qo.businessId})
                        </script>
                        <div class="form-group">
                            <label>时间段查询:</label>
                            <div class="input-daterange input-group">
                                <input type="text" class="input-sm form-control" id="beginDate" name="beginDate"
                                       value="${(qo.beginDate?string("yyyy-MM-dd HH:mm"))!}"/>
                                <span class="input-group-addon">到</span>
                                <input type="text" class="input-sm form-control" id="endDate" name="endDate"
                                       value="${(qo.endDate?string("yyyy-MM-dd HH:mm"))!}"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>结算单状态</label>
                            <select class="form-control" name="status" id="status">
                                <option value="">全部</option>
                                <#list status as tmp>
                                    <option value="${tmp.getValue()}">${tmp.getName()}</option>
                                </#list>
                            </select>
                        </div>
                        <script>
                            $("#status").val(${qo.status})
                        </script>
                        <div class="form-group">
                            <label>预约类型</label>
                            <select class="form-control" name="aType" id="aType">
                                <option value="">请选择预约类型</option>
                                <option value="1">预约</option>
                                <option value="0">非预约</option>
                            </select>
                        </div>
                        <script>
                            $("#aType").val(${qo.AType})
                        </script>

                        <br/>
                        <br/>

                        <div class="form-group">
                            <label for="status">分组类型:</label>
                            <select class="form-control" name="condition" id="condition">
                                <option value="b.name">门店</option>
                                <option value="year(c.pay_time)">年</option>
                                <option value="month(c.pay_time)">月</option>
                                <option value="day(c.pay_time)">日</option>
                            </select>
                        </div>

                        <script>
                            $("#condition").val('${qo.condition}')
                        </script>

                        <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>
                        <button type="button" class="btn btn-info btn-chart" id="zhu">
                            <span class="glyphicon glyphicon-stats"></span> 柱状图
                        </button>

                        <button type="button" class="btn btn-info btn-chart" id="bing">
                            <span class="glyphicon glyphicon-stats"></span> 饼状图
                        </button>
                    </form>
                    <span data-json='${chart.json}' id="chartData"></span>
                    <span data-json='${chart.json}' id="json"></span>

                    <#list chart.pay as tmp>
                        ${tmp}
                    </#list>
                </div>
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <thead>
                        <tr>
                            <th>分组类型</th>
                            <th>总订单数</th>
                            <th>总消费金额</th>
                            <th>总实收金额</th>
                            <th>总优惠金额</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list result.list as tmp>
                            <tr>
                                <td>${tmp.cond}</td>
                                <td>${tmp.count}</td>
                                <td>${tmp.total}</td>
                                <td>${tmp.pay}</td>
                                <td>${tmp.discount}</td>
                            </tr>
                        </#list>

                        </tbody>

                    </table>
                    <#include "/common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>


<!-- Modal模态框 -->
<div class="modal fade" id="chartModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" style="padding: 20px">

            <div id="main" style="width: 600px;height:400px;"></div>
        </div>


        <script type="text/javascript">
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('main'));

            // 指定图表的配置项和数据
            option = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        crossStyle: {
                            color: '#999'
                        }
                    }
                },
                toolbox: {
                    feature: {
                        dataView: {show: true, readOnly: false},
                        magicType: {show: true, type: ['line', 'bar']},
                        restore: {show: true},
                        saveAsImage: {show: true}
                    }
                },
                legend: {
                    data: ['总收入', '总实收', '总打折', '总数量']
                },
                xAxis: [
                    {
                        type: 'category',
                        data: $("#chartData").data("json").cond,
                        axisPointer: {
                            type: 'shadow'
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: '金额',
                        // min: 0,
                        // max: 250,
                        // interval: 50,
                        axisLabel: {
                            formatter: '{value} 元'
                        }
                    },
                    {
                        type: 'value',
                        name: '数量',
                        // min: 0,
                        // max: 25,
                        // interval: 5,
                        axisLabel: {
                            formatter: '{value} 个'
                        }
                    }
                ],
                series: [
                    {
                        name: '总收入',
                        type: 'bar',
                        data: $("#chartData").data("json").total
                    },
                    {
                        name: '总实收',
                        type: 'bar',
                        data: $("#chartData").data("json").pay
                    },
                    {
                        name: '总数量',
                        type: 'line',
                        yAxisIndex: 1,
                        data: $("#chartData").data("json").count
                    },
                    {
                        name: '总打折',
                        type: 'bar',
                        data: $("#chartData").data("json").discount
                    }
                ]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        </script>
    </div>
</div>

<div class="modal fade" id="bingModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" style="padding: 20px">
            <div id="bingmain" style="width: 600px;height:400px;"></div>
        </div>

        <script>
            var myChart = echarts.init(document.getElementById("bingmain"));
            var arr = [];
            var arr1 = [];
            var arr2 = [];
            var arr3 = [];
            console.log($("#json").data("json"));
            for (var i = 0; i < $("#json").data("json").cond.length; i++) {
                var s = {value: '', name: ''}
                s.value = $("#json").data("json").total[i];
                s.name = $("#json").data("json").cond[i];
                arr.push(s);
            }
            for (var i = 0; i < $("#json").data("json").cond.length; i++) {
                var s = {value: '', name: ''}
                s.value = $("#json").data("json").pay[i];
                s.name = $("#json").data("json").cond[i];
                arr1.push(s);
            }
            for (var i = 0; i < $("#json").data("json").cond.length; i++) {
                var s = {value: '', name: ''}
                s.value = $("#json").data("json").discount[i];
                s.name = $("#json").data("json").cond[i];
                arr2.push(s);
            }
            for (var i = 0; i < $("#json").data("json").count.length; i++) {
                var s = {value: '', name: ''}
                s.value = $("#json").data("json").count[i];
                s.name = $("#json").data("json").cond[i];
                arr3.push(s);
            }
            console.log(arr)
            console.log(arr1)
            console.log(arr2)
            console.log(arr3)
            var option = {
                title: {
                    text: '门店收入一览',
                    subtext: '饼状图分析',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: '总消费金额',
                        type: 'pie',
                        radius: ['90%', '80%'],
                        data: arr,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 1, 0.5)'
                            }
                        }
                    },
                    {
                        name: '总实收金额',
                        type: 'pie',
                        radius: ['49%', '64%'],
                        data: arr1,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(500, 1, 0, 1)'
                            }
                        }
                    },
                    {
                        name: '总优惠金额',
                        type: 'pie',
                        radius: ['33%', '48%'],
                        data: arr2,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 2)'
                            }
                        }
                    },
                    {
                        name: '订单数',
                        type: 'pie',
                        radius: '32%',
                        data: arr3,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 2)'
                            }
                        }
                    }
                ]
            };

            myChart.clear();
            myChart.setOption(option);

            myChart.setOption(option);
        </script>
    </div>
</div>


<script>
    $("#zhu").click(function () {
        $("#chartModal").modal("show")
    })
    $("#bing").click(function () {
        $("#bingModal").modal("show")
    })
</script>
</body>
</html>